#ifndef REFEREE_H
#define REFEREE_H
#include "main.h"
typedef enum
{
    RED_HERO        = 1,
    RED_ENGINEER    = 2,
    RED_STANDARD_1  = 3,
    RED_STANDARD_2  = 4,
    RED_STANDARD_3  = 5,
    RED_AERIAL      = 6,
    RED_SENTRY      = 7,
    BLUE_HERO       = 11,
    BLUE_ENGINEER   = 12,
    BLUE_STANDARD_1 = 13,
    BLUE_STANDARD_2 = 14,
    BLUE_STANDARD_3 = 15,
    BLUE_AERIAL     = 16,
    BLUE_SENTRY     = 17,
} robot_id_t;
typedef enum
{
    PROGRESS_UNSTART        = 0,
    PROGRESS_PREPARE        = 1,
    PROGRESS_SELFCHECK      = 2,
    PROGRESS_5sCOUNTDOWN    = 3,
    PROGRESS_BATTLE         = 4,
    PROGRESS_CALCULATING    = 5,
} game_progress_t;
typedef enum
{
    GAME_STATE_CMD_ID                 = 0x0001,
    GAME_RESULT_CMD_ID                = 0x0002,
    GAME_ROBOT_HP_CMD_ID              = 0x0003,
	DART_STATUS_CMD_ID            	  = 0x0004,
	IRCA_BUFF_DEBUFF_ZONE_STATUS  	  = 0x0005,
    FIELD_EVENTS_CMD_ID               = 0x0101,
    SUPPLY_PROJECTILE_ACTION_CMD_ID   = 0x0102,
    SUPPLY_PROJECTILE_BOOKING_CMD_ID  = 0x0103,
    REFEREE_WARNING_CMD_ID            = 0x0104,
	DART_REMAINING_TIME_CMD_ID        = 0x0105,
    ROBOT_STATE_CMD_ID                = 0x0201,
    POWER_HEAT_DATA_CMD_ID            = 0x0202,
    ROBOT_POS_CMD_ID                  = 0x0203,
    BUFF_MUSK_CMD_ID                  = 0x0204,
    AERIAL_ROBOT_ENERGY_CMD_ID        = 0x0205,
    ROBOT_HURT_CMD_ID                 = 0x0206,
    SHOOT_DATA_CMD_ID                 = 0x0207,
    BULLET_REMAINING_CMD_ID           = 0x0208,
	RFID_STATUS_CMD_ID                = 0x0209,
	DART_CLIENT_CMD_ID                = 0x020A,
    STUDENT_INTERACTIVE_DATA_CMD_ID   = 0x0301,
    ROBOT_INTERACTIVE_DATA_CMD_ID     = 0x0302,
	ROBOT_CMD_ID                  	  = 0x0303,
	RC_CMD_ID                     	  = 0x0304,
    IDCustomData,
}referee_cmd_id_t;
typedef __packed struct
{
    uint8_t  sof;
    uint16_t dataLenth;
    uint8_t  seq;
    uint8_t  crc8;
} tFrameHeader;
typedef __packed struct 
{  
	uint8_t game_type : 4;   
	uint8_t game_progress : 4;   
	uint16_t stage_remain_time; 
	uint64_t SyncTimeStamp; 
} ext_game_status_t;
typedef __packed struct //0x002
{    
	uint8_t winner; 
} ext_game_result_t; 
typedef __packed struct //0x003
{  
	uint16_t red_1_robot_HP;    
	uint16_t red_2_robot_HP;  
	uint16_t red_3_robot_HP;  
	uint16_t red_4_robot_HP;  
	uint16_t red_5_robot_HP;   
	uint16_t red_7_robot_HP; 
	uint16_t red_outpost_HP;  
	uint16_t red_base_HP;    
	uint16_t blue_1_robot_HP;  
	uint16_t blue_2_robot_HP;  
	uint16_t blue_3_robot_HP;    
	uint16_t blue_4_robot_HP;   
	uint16_t blue_5_robot_HP;   
	uint16_t blue_7_robot_HP; 
	uint16_t blue_outpost_HP;  
	uint16_t blue_base_HP; 
} ext_game_robot_HP_t; 
typedef __packed struct//0x004
{  
	uint8_t dart_belong;  
	uint16_t stage_remaining_time; 
} ext_dart_status_t;
typedef __packed struct //0x005
{
	uint8_t F1_zone_status:1;  
	uint8_t F1_zone_buff_debuff_status:3;    
	uint8_t F2_zone_status:1;   
	uint8_t F2_zone_buff_debuff_status:3;   
	uint8_t F3_zone_status:1;  
	uint8_t F3_zone_buff_debuff_status:3;   
	uint8_t F4_zone_status:1;  
	uint8_t F4_zone_buff_debuff_status:3; 
	uint8_t F5_zone_status:1;  
	uint8_t F5_zone_buff_debuff_status:3; 
	uint8_t F6_zone_status:1; 
	uint8_t F6_zone_buff_debuff_status:3;   
	uint16_t red1_bullet_left;  
	uint16_t red2_bullet_left;
	uint16_t blue1_bullet_left; 
	uint16_t blue2_bullet_left; 
} ext_ICRA_buff_debuff_zone_status_t; 
typedef __packed struct //0x101
{
	uint32_t event_type;
} ext_event_data_t;
typedef __packed struct //0x102
{
    uint8_t supply_projectile_id;
    uint8_t supply_robot_id;
    uint8_t supply_projectile_step;
    uint8_t supply_projectile_num;
} ext_supply_projectile_action_t;
typedef __packed struct //0x103
{
    uint8_t supply_projectile_id;
    uint8_t supply_robot_id;
    uint8_t supply_num;
} ext_supply_projectile_booking_t;
typedef __packed struct//0x104
{
    uint8_t level;
    uint8_t foul_robot_id;
} ext_referee_warning_t;
typedef __packed struct //0x105
{   
	uint8_t dart_remaining_time;  
} ext_dart_remaining_time_t; 
typedef __packed struct //0x0201
{
	uint8_t robot_id;
	uint8_t robot_level;
	uint16_t remain_HP;
	uint16_t max_HP;
	uint16_t shooter_id1_17mm_cooling_rate;
	uint16_t shooter_id1_17mm_cooling_limit;
	uint16_t shooter_id1_17mm_speed_limit;
	uint16_t shooter_id2_17mm_cooling_rate;
	uint16_t shooter_id2_17mm_cooling_limit;
	uint16_t shooter_id2_17mm_speed_limit;
	uint16_t shooter_id1_42mm_cooling_rate;
	uint16_t shooter_id1_42mm_cooling_limit;
	uint16_t shooter_id1_42mm_speed_limit;
	uint16_t chassis_power_limit;
	uint8_t mains_power_gimbal_output : 1;
	uint8_t mains_power_chassis_output : 1;
	uint8_t mains_power_shooter_output : 1;
} ext_game_robot_status_t;
typedef __packed struct //0x0202
{
	uint16_t chassis_volt;
	uint16_t chassis_current;
	float chassis_power;
	uint16_t chassis_power_buffer;
	uint16_t shooter_id1_17mm_cooling_heat;
	uint16_t shooter_id2_17mm_cooling_heat;
	uint16_t shooter_id1_42mm_cooling_heat;
} ext_power_heat_data_t;
typedef __packed struct //0x0203
{
	float x;
    float y;
    float z;
    float yaw;
} ext_game_robot_pos_t;
typedef __packed struct //0x0204
{
	uint8_t power_rune_buff;
} ext_buff_musk_t;
typedef __packed struct //0x0205
{
    uint8_t attack_time;
} aerial_robot_energy_t;
typedef __packed struct //0x0206
{
    uint8_t armor_type : 4;
    uint8_t hurt_type : 4;
} ext_robot_hurt_t;
typedef __packed struct//0x207 
{   
	uint8_t bullet_type;  
	uint8_t shooter_id;   
	uint8_t bullet_freq;    
	float bullet_speed;  
} ext_shoot_data_t; 
typedef __packed struct//0x208
{
	uint16_t bullet_remaining_num_17mm;   
	uint16_t bullet_remaining_num_42mm; 
	uint16_t coin_remaining_num; 
} ext_bullet_remaining_t;

typedef __packed struct //0x209
{  
	uint32_t rfid_status;
} ext_rfid_status_t; 
typedef __packed struct//0x20A 
{   
	uint8_t dart_launch_opening_status;   
	uint8_t dart_attack_target; 
	uint16_t target_change_time;   
	uint8_t first_dart_speed;
	uint8_t second_dart_speed;  
	uint8_t third_dart_speed;   
	uint8_t fourth_dart_speed;  
	uint16_t last_dart_launch_time;
	uint16_t operate_launch_cmd_time; 
} ext_dart_client_cmd_t;
typedef __packed struct //0x301
{   
	uint16_t data_cmd_id;    
	uint16_t sender_ID;    
	uint16_t receiver_ID;
}ext_student_interactive_data_t;
typedef __packed struct//0x303
{
	float target_position_x;
	float target_position_y;
	float target_position_z;
	uint8_t commd_keyboard;
	uint16_t target_robot_ID;
} ext_robot_command_t;
typedef __packed struct//0x304
{
	int16_t mouse_x;
	int16_t mouse_y;
	int16_t mouse_z;
	int8_t left_button_down;
	int8_t right_button_down;
	uint16_t keyboard_value;
	uint16_t reserved;
} ext_rc_command_t;
typedef __packed struct
{
    float data1;
    float data2;
    float data3;
    uint8_t data4;
} custom_data_t;
typedef __packed struct
{
	uint8_t data[64];
} ext_up_stream_data_t;
typedef __packed struct
{
	uint8_t data[32];
} ext_download_stream_data_t;
typedef struct
{
	ext_supply_projectile_action_t projectile_data;
	ext_event_data_t       event_data;
	ext_buff_musk_t        buff_data;
	ext_game_robot_status_t robot_state;
	ext_power_heat_data_t chassis_power_info;
	ext_shoot_data_t shoot_data;
} receive_judge_t;

extern receive_judge_t judge_rece_mesg;
extern ext_game_status_t game_state;
extern ext_game_result_t game_result;
extern ext_game_robot_HP_t game_robot_HP_t;
extern ext_dart_status_t dart_status_t;
extern ext_ICRA_buff_debuff_zone_status_t ICRA_buff_debuff_zone_status_t;
extern ext_event_data_t field_event;
extern ext_supply_projectile_action_t supply_projectile_action_t;
extern ext_supply_projectile_booking_t supply_projectile_booking_t;
extern ext_referee_warning_t referee_warning_t;
extern ext_dart_remaining_time_t dart_remaining_time_t;
extern ext_game_robot_status_t robot_state;
extern ext_power_heat_data_t power_heat_data_t;
extern ext_game_robot_pos_t game_robot_pos_t;
extern ext_buff_musk_t buff_musk_t;
extern aerial_robot_energy_t robot_energy_t;
extern ext_robot_hurt_t robot_hurt_t;
extern ext_shoot_data_t shoot_data_t;
extern ext_bullet_remaining_t bullet_remaining_t;
extern ext_rfid_status_t rfid_status_t;
extern ext_dart_client_cmd_t dart_client_cmd_t;
extern ext_student_interactive_data_t student_interactive_data_t;
extern ext_robot_command_t robot_command_t;
extern ext_rc_command_t rc_command_t;

extern void init_referee_struct_data(void);
extern void referee_data_solve(uint8_t *frame);
#endif
